package com.memory.api.service.dubboService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.memory.common.model.entity.InterfaceInfo;
import com.memory.common.common.ErrorCode;
import com.memory.common.exception.BusinessException;
import com.memory.api.mapper.InterfaceInfoMapper;
import com.memory.common.service.dubboService.InterfaceInfoDubboService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * 内部接口服务实现类
 *
 * @author memory
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InterfaceInfoDubboService {

    @Resource
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 请求的模拟接口是否存在
     *
     * @param url    请求 url
     * @param method 请求 方法
     * @return 接口信息
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String url, String method) {
        if (StringUtils.isAnyBlank(url, method)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url", url);
        queryWrapper.eq("method", method);

        // 获取接口信息
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
